/**
 * gzool window
 * http://gzool.com/
 * Released into the public domain
 * Date: Jan 22th 2009
 * @author Johnason
 * @version 1.0
 *
 * Basic calling syntax: $("input").labelify();
 * Defaults to taking the in-field label from the field's title attribute
 *
 */
jQuery.fn.gzoolWindow = function(props) {
    props = jQuery.extend({
        width: "400",
        height: "400",
        position: "relative",
        top: "0px",
        left: "0px",
        closeBtn: false,
        closeFunc: function(){
        }
    }, props);

	return $(this).each(
	  function() {
		  var winId = "regeWin"+Math.round(Math.random()*100)+"Inner";
		  var insidehtml = $(this).html();
		  
		  var bg_fnFixPng = function(obj) {
			var mode = 'scale';
			var bg	= obj.currentStyle.backgroundImage;
			var src = bg.substring(5,bg.length-2);
			if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
				mode = 'crop';
			}
			obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
			obj.style.backgroundImage = 'url('+BLANK_IMAGE_URL+')';
		  };
		  // avoid name conflict
		  var bgClassName = "bgPng-"+winId;
		  var newhtml = '<div id="'+winId+'" class="gzoolWindow">'+
						'<div class="gzoolWindowPanel">'+
							'<div class="gzoolWindowPanelNW '+bgClassName+'"></div>'+
							'<div class="gzoolWindowPanelN"></div>'+
							'<div class="gzoolWindowPanelNE '+bgClassName+'"></div>'+
							'<div class="gzoolWindowPanelW"></div>'+
							'<div class="gzoolWindowPanelE"></div>'+
							'<div class="gzoolWindowPanelS"></div>'+
							'<div class="gzoolWindowPanelSW '+bgClassName+'"></div>'+
							'<div class="gzoolWindowPanelSE '+bgClassName+'"></div>'+
							'<div class="gzoolWindowPanelMid">'+
							'<div class="clear"></div>'+
								'<div class="btn-black-close"></div>'+
								insidehtml+
							'</div>'+
						'</div>'+
						'<div class="gzoolWindowShadow">'+
							'<div class="gzoolWindowShadowNE '+bgClassName+'"></div>'+
							'<div class="gzoolWindowShadowNW '+bgClassName+'"></div>'+
							'<div class="gzoolWindowShadowN '+bgClassName+'"></div>'+
							'<div class="gzoolWindowShadowSW '+bgClassName+'"></div>'+
							'<div class="gzoolWindowShadowS  '+bgClassName+'"></div>'+
							'<div class="gzoolWindowShadowSE '+bgClassName+'"></div>'+
							'<div class="gzoolWindowShadowE '+bgClassName+'"></div>'+
							'<div class="gzoolWindowShadowW '+bgClassName+'"></div>'+
						'</div>'+
					'</div>';
		  $(this).html( newhtml );
		  
		  $('#'+winId).css({"width":props.width+'px', "height":props.height+'px', "position":props.position, "top":props.top, "left":props.left});
		  var panelWidth = (parseInt(props.width)-25)+'px';
		  var panelHeight = (parseInt(props.height)-25)+'px';
		  $('#'+winId+' .gzoolWindowPanel').css({"width":panelWidth,"height":panelHeight});
		  $('#'+winId+' .gzoolWindowPanelN').css({"width":panelWidth});
		  $('#'+winId+' .gzoolWindowPanelW').css({"height":panelHeight});
		  $('#'+winId+' .gzoolWindowPanelS').css({"width":panelWidth});
		  $('#'+winId+' .gzoolWindowPanelE').css({"height":panelHeight});
		  var shadowWidth = (parseInt(props.width)-26)+'px';
		  var shadowHeight = (parseInt(props.height)-26)+'px';
		  $('#'+winId+' .gzoolWindowShadow').css({"width":shadowWidth,"height":shadowHeight});
		  $('#'+winId+' .gzoolWindowShadowN').css({"width":shadowWidth});
		  $('#'+winId+' .gzoolWindowShadowW').css({"height":shadowHeight});
		  $('#'+winId+' .gzoolWindowShadowS').css({"width":shadowWidth});
		  $('#'+winId+' .gzoolWindowShadowE').css({"height":shadowHeight});
		  
		  if( props.closeBtn == false )
			  $('#'+winId+' .btn-black-close').css({"display":"none"});
		  else{
			  $('#'+winId+' .btn-black-close').css({"display":"block"});
			  $('#'+winId+' .btn-black-close').bind( "click", props.closeFunc);
		  }
		  
		  if($.browser.msie && (jQuery.browser.version.substr(0,1)< "7")){
			  $('#'+winId+' .'+bgClassName).each(function(){
				  bg_fnFixPng(this);
			  });
		  }
	  });
};




jQuery.fn.gzoolTitleWindow = function(props) {
	props = jQuery.extend({
		width: "400",
		height: "400",
		title: "",
		position: "relative",
		top: "0px",
		left: "0px",
		closeBtn: false,
		closeFunc: function(){}
	}, props); 
	
	return $(this).each(
	  function() {
		  var winId = "regeWin"+Math.round(Math.random()*100)+"Inner";
		  var insidehtml = $(this).html();
		  
		  var bg_fnFixPng = function(obj) {
			var mode = 'scale';
			var bg	= obj.currentStyle.backgroundImage;
			var src = bg.substring(5,bg.length-2);
			if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
				mode = 'crop';
			}
			obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
			obj.style.backgroundImage = 'url('+BLANK_IMAGE_URL+')';
		  };
		  // avoid name conflict
		  var bgClassName = "bgPng-"+winId;
		  var newhtml = '<div id="'+winId+'" class="gzoolTitleWindow">'+
							'<div class="gzoolTitleWindowPanel">'+
								'<div class="gzoolTitleWindowPanelN"></div>'+
								'<div class="gzoolTitleWindowPanelNW '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowPanelNE '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowTitleW"></div>'+
								'<div class="gzoolTitleWindowTitleMid">'+
									'<div class="btn-white-close"></div>'+
									props.title+
								'</div>'+
								'<div class="gzoolTitleWindowTitleE"></div>'+
								
								'<div class="gzoolTitleWindowPanelW"></div>'+
								'<div class="gzoolTitleWindowPanelE"></div>'+
								'<div class="gzoolTitleWindowPanelS"></div>'+
								'<div class="gzoolTitleWindowPanelSW '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowPanelSE '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowPanelMid">'+
									insidehtml+
								'</div>'+
							'</div>'+
							'<div class="gzoolTitleWindowShadow">'+
								'<div class="gzoolTitleWindowShadowNE '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowShadowNW '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowShadowN '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowShadowSW '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowShadowS '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowShadowSE '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowShadowE '+bgClassName+'"></div>'+
								'<div class="gzoolTitleWindowShadowW '+bgClassName+'"></div>'+
							'</div>'+
						'</div>';
	
		  $(this).html( newhtml );

		  $('#'+winId).css({"width":props.width+'px', "height":props.height+'px', "position":props.position, "top":props.top, "left":props.left});
		  var panelWidth = (parseInt(props.width)-25)+'px';
		  var panelHeight = (parseInt(props.height)-45)+'px';
		  $('#'+winId+' .gzoolTitleWindowPanel').css({"width":panelWidth,"height":panelHeight});
		  $('#'+winId+' .gzoolTitleWindowPanelN').css({"width":panelWidth});
		  $('#'+winId+' .gzoolTitleWindowPanelW').css({"height":panelHeight});
		  $('#'+winId+' .gzoolTitleWindowPanelS').css({"width":panelWidth});
		  $('#'+winId+' .gzoolTitleWindowPanelE').css({"height":panelHeight});
		  var shadowWidth = (parseInt(props.width)-26)+'px';
		  var shadowHeight = (parseInt(props.height)-26)+'px';
		  $('#'+winId+' .gzoolTitleWindowShadow').css({"width":shadowWidth,"height":shadowHeight});
		  $('#'+winId+' .gzoolTitleWindowShadowN').css({"width":shadowWidth});
		  $('#'+winId+' .gzoolTitleWindowShadowW').css({"height":shadowHeight});
		  $('#'+winId+' .gzoolTitleWindowShadowS').css({"width":shadowWidth});
		  $('#'+winId+' .gzoolTitleWindowShadowE').css({"height":shadowHeight});
		  
		  if( props.closeBtn == false )
			  $('#'+winId+' .btn-white-close').css({"display":"none"});
		  else{
			  $('#'+winId+' .btn-white-close').css({"display":"block"});
			  $('#'+winId+' .btn-white-close').bind( "click", props.closeFunc);
		  }
		  
		  if($.browser.msie && (jQuery.browser.version.substr(0,1)< "7")){
			  $('#'+winId+' .'+bgClassName).each(function(){
				  bg_fnFixPng(this);
			  });
		  }
	  });
};